/*
 * Copyright (C) 2011, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.model;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import xowl.utils.config.Configuration;
import xowl.utils.config.Section;

/**
 *
 * @author Laurent WOUTERS
 */
public class Workbench {
    private List<String> metamodels;
    private Map<String, WorkbenchView> views;
    private Map<String, ExecutionEntry> execEntries;
    
    public Collection<WorkbenchView> getViews() { return views.values(); }
    public WorkbenchView getView(String id) { return views.get(id); }
    public Collection<ExecutionEntry> getExecEntries() { return execEntries.values(); }
    public ExecutionEntry getExecEntry(String id) { return execEntries.get(id); }
    
    public Workbench() {
        this.metamodels = new ArrayList<>();
        this.views = new HashMap<>();
        this.execEntries = new HashMap<>();
    }
    public Workbench(String file) throws IOException {
        Configuration config = new Configuration();
        config.load(file);
        this.metamodels = new ArrayList<>(config.getValues("metamodel"));
        this.views = new HashMap<>();
        this.execEntries = new HashMap<>();
        for (String view : config.getValues("view"))
            views.put(view, new WorkbenchView(config, view));
        for (String exec : config.getValues("exec"))
            execEntries.put(exec, new ExecutionEntry(config.getGlobalSection(), exec));
    }
    
    public void load(xowl.interpreter.Repository repository) {
        for (String metamodel : metamodels)
            repository.loadOntology(metamodel, xowl.interpreter.OWL2Syntax.Functional);
        for (WorkbenchView view : views.values())
            view.load(repository);
    }
}
